﻿Shader "Hidden/SimpleBlurEffect"
{

	Properties
	{
		_MainTex("Base (RGB)", 2D) = "white" {}
	}


		CGINCLUDE

#include "UnityCG.cginc"


struct v2f_blur
	{
		float4 pos : SV_POSITION; 
		float2 uv  : TEXCOORD0;	 
		float2 uv1 : TEXCOORD1; 

	};


	sampler2D _MainTex;

	float4 _MainTex_TexelSize;

	float _BlurRadius;

	//vertex shader
	v2f_blur vert_blur(appdata_img v)
	{
		v2f_blur o;
		o.pos = UnityObjectToClipPos(v.vertex);
		o.uv = v.texcoord.xy;

	
		return o;
	}

	fixed4 frag_blur(v2f_blur i) : SV_Target
	{
		fixed4 color = fixed4(0,0,0,0);

		color = max(color,tex2D(_MainTex, i.uv ));
		color = max(color, tex2D(_MainTex, i.uv + _BlurRadius * _MainTex_TexelSize * float2(1, 1)));
		color = max(color, tex2D(_MainTex, i.uv + _BlurRadius * _MainTex_TexelSize * float2(-1, 1)));
		color = max(color, tex2D(_MainTex, i.uv + _BlurRadius * _MainTex_TexelSize * float2(-1, -1)));
		color = max(color, tex2D(_MainTex, i.uv + _BlurRadius * _MainTex_TexelSize * float2(1, -1)));

	
		return color;
	}

		ENDCG

		//子着色器
		SubShader
	{
		//pass 0: blur effect
		Pass
		{
			ZTest Always
			Cull Off
			ZWrite Off
			Fog{ Mode Off }

			//直接调用vert_blur和frag_blur
			CGPROGRAM
			#pragma vertex vert_blur
			#pragma fragment frag_blur
			ENDCG
		}
	}
}
